package com.example.administrator.qimo3no74.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.qimo3no74.OrdersActivity;
import com.example.administrator.qimo3no74.R;
import com.example.administrator.qimo3no74.my.OrderIcon;
import com.example.administrator.qimo3no74.my.OrderIconAdapter;
import com.example.administrator.qimo3no74.my.ToolIcon;
import com.example.administrator.qimo3no74.my.ToolIconAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class MyFragment extends Fragment {
    private TextView myTextViewShouCangNum ;
    private TextView myTextViewShouCang ;
    private TextView myTextViewFollowNum ;
    private TextView myTextViewFollow ;
    private TextView myTextViewFootprintNum ;
    private TextView myTextViewFootprint ;
    private TextView myTextViewCartNum ;
    private TextView myTextViewCart ;
    private TextView myTextViewName;
    private TextView myTextViewAllOrder;
    private TextView myTextViewAllTool;
    private TextView myTextViewManageCart;
    private TextView myTextViewOtherService;


    private List<OrderIcon> orderIcons = new ArrayList<>();
    private List<ToolIcon> toolIcons = new ArrayList<>();

    public MyFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_my, container, false);

        //控件赋值
        intiIN(view);

        //点击事件
        allOnClick();

        //我的订单图标
        initOrderIcon();
        actionOrderIcon(view);

        //我的工具图标
        initToolIcon();
        actionToolIcon(view);


        return view;
    }

    private void allOnClick() {
        myTextViewShouCangNum.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), myTextViewShouCangNum.getText()+"", Toast.LENGTH_SHORT).show();
            }
        });

        myTextViewShouCang.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), myTextViewShouCang.getText()+"", Toast.LENGTH_SHORT).show();
            }
        });
        myTextViewFollowNum.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), myTextViewFollowNum.getText()+"", Toast.LENGTH_SHORT).show();
            }
        });
        myTextViewFollow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), myTextViewFollow.getText()+"", Toast.LENGTH_SHORT).show();
            }
        });
        myTextViewFollow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), myTextViewFollow.getText()+"", Toast.LENGTH_SHORT).show();
            }
        });
        myTextViewFootprintNum.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), myTextViewFootprintNum.getText()+"", Toast.LENGTH_SHORT).show();
            }
        });
        myTextViewFootprintNum.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), myTextViewFootprintNum.getText()+"", Toast.LENGTH_SHORT).show();
            }
        });
        myTextViewFootprint.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), myTextViewFootprint.getText()+"", Toast.LENGTH_SHORT).show();
            }
        });
        myTextViewCart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), myTextViewCart.getText()+"", Toast.LENGTH_SHORT).show();
            }
        });

        myTextViewName.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), myTextViewName.getText()+"", Toast.LENGTH_SHORT).show();
            }
        });

        myTextViewAllOrder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(v.getContext(),OrdersActivity.class);
                v.getContext().startActivity(intent);
            }
        });

        myTextViewAllTool.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), "我们会研发更改实用的工具哦", Toast.LENGTH_SHORT).show();
            }
        });
        myTextViewManageCart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), "你的卡片除了您需要管理，我们也会帮您管理哦", Toast.LENGTH_SHORT).show();
            }
        });

        myTextViewOtherService.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), "使用支付宝还有很多省钱的方法哦", Toast.LENGTH_SHORT).show();
            }
        });

    }

    private void intiIN(View view) {
        myTextViewShouCangNum = view.findViewById(R.id.myTextViewShouCangNum);
        myTextViewShouCang = view.findViewById(R.id.myTextViewShouCang);
        myTextViewFollowNum = view.findViewById(R.id.myTextViewFollowNum);
        myTextViewFollow = view.findViewById(R.id.myTextViewFollow);
        myTextViewFootprintNum = view.findViewById(R.id.myTextViewFootprintNum);
        myTextViewFootprint = view.findViewById(R.id.myTextViewFootprint);
        myTextViewCartNum = view.findViewById(R.id.myTextViewCartNum);
        myTextViewCart = view.findViewById(R.id.myTextViewCart);
        myTextViewName = view.findViewById(R.id.myTextViewName);
        myTextViewAllOrder = view.findViewById(R.id.myTextViewAllOrder);
        myTextViewAllTool = view.findViewById(R.id.myTextViewAllTool);
        myTextViewManageCart = view.findViewById(R.id.myTextViewManageCart);
        myTextViewOtherService = view.findViewById(R.id.myTextViewOtherService);
    }

    private void actionToolIcon(View view) {
        RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.myRecyclerView2);
        GridLayoutManager layoutManager = new GridLayoutManager(getActivity(),4);
        recyclerView.setLayoutManager(layoutManager);
        ToolIconAdapter adapter = new ToolIconAdapter(toolIcons);
        recyclerView.setAdapter(adapter);

    }

    private void initToolIcon() {
        toolIcons.add(new ToolIcon("我的问答",R.drawable.ic_my_answer));
        toolIcons.add(new ToolIcon("领劵中心",R.drawable.ic_my_juan));
        toolIcons.add(new ToolIcon("闲置换钱",R.drawable.ic_my_money));
        toolIcons.add(new ToolIcon("客服小蜜",R.drawable.ic_my_kefu));
        toolIcons.add(new ToolIcon("花呗",R.drawable.ic_my_huabei));
        toolIcons.add(new ToolIcon("啊里发票",R.drawable.ic_my_invoice));
        toolIcons.add(new ToolIcon("我的评价",R.drawable.ic_my_evaluate));
        toolIcons.add(new ToolIcon("主题换肤",R.drawable.ic_my_theme));
    }

    private void actionOrderIcon(View view) {
        RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.myRecyclerView1);
        GridLayoutManager layoutManager = new GridLayoutManager(getActivity(),5);
        recyclerView.setLayoutManager(layoutManager);
        OrderIconAdapter adapter = new OrderIconAdapter(orderIcons);
        recyclerView.setAdapter(adapter);
    }

    private void initOrderIcon() {
        orderIcons.add(new OrderIcon("待付款",R.drawable.ic_pending_payment));
        orderIcons.add(new OrderIcon("待发货",R.drawable.ic_shipped));
        orderIcons.add(new OrderIcon("待收货",R.drawable.ic_received));
        orderIcons.add(new OrderIcon("评价",R.drawable.ic_evaluate));
        orderIcons.add(new OrderIcon("退款/售后",R.drawable.ic_refund));

    }

}
